#pragma once
#include <mutex>
#include <condition_variable>
#include <thread>
#include <queue>
#include <iostream>
using namespace std;

template<class T>
class blockQueue
{
public:
	blockQueue(int size=num)
		:_num(num)
	{}
	~blockQueue()
	{}
	void push(const T& t)
	{
		unique_lock<mutex> lock(_mtx);
		_condProduct.wait(lock, [&]() {return _q.size() < _num; });
		_q.push(t);
		count << "producter->" << t << endl;
		_condConsume.notify_all();
	}
	void pop()
	{
		unique_lock<mutex> lock(_mtx);
		_condConsume.wait(lock, [&]() {return !_q.empty(); });
		T t = _q.front();
		_q.pop();
		cout << "consumer->" << t << endl;
		_condProduct.notify_all();
	}
private:
	queue<T> _q;
	int _num;

	mutex _mtx;
	condition_variable _condProduct;
	condition_variable _condConsume;
};

